VERSION 5.00 Begin VB.Form frmNames BorderStyle = 3 'Fixed Dialog Caption = "Names" ClientHeight = 2775 ClientLeft = 45 ClientTop = 330 ClientWidth = 5850 LinkTopic = "Form1" MaxButton = 0 'False MinButton = 0 'False ScaleHeight = 2775 ScaleWidth = 5850 ShowInTaskbar = 0 'False StartUpPosition = 3 'Windows Default Begin VB.CommandButton cmdName Height = 375 Index = 0 Left = 2265 Picture = "frmNames.frx":0000 Style = 1 'Graphical TabIndex = 17 TabStop = 0 'False ToolTipText = "New" Top = 2190 Width = 375 End Begin VB.CommandButton cmdName Height = 375 Index = 1 Left = 2625 Picture = "frmNames.frx":0216 Style = 1 'Graphical TabIndex = 16 ToolTipText = "Save" Top = 2190 Width = 375 End Begin VB.CommandButton cmdName Height = 375 Index = 2 Left = 2985 Picture = "frmNames.frx":04C0 Style = 1 'Graphical TabIndex = 15 ToolTipText = "Cancel" Top = 2190 Width = 375 End Begin VB.CommandButton cmdName Height = 375 Index = 3 Left = 3345 Picture = "frmNames.frx":07D2 Style = 1 'Graphical TabIndex = 14 TabStop = 0 'False ToolTipText = "Delete" Top = 2190 Width = 375 End Begin VB.CommandButton cmdName Height = 375 Index = 4 Left = 3705 Picture = "frmNames.frx":095C Style = 1 'Graphical TabIndex = 13 TabStop = 0 'False ToolTipText = "Next" Top = 2190 Width = 375 End Begin VB.CommandButton cmdName Height = 375 Index = 5 Left = 1905 Picture = "frmNames.frx":0A2E Style = 1 'Graphical TabIndex = 12 TabStop = 0 'False ToolTipText = "Previous" Top = 2190 Width = 375 End Begin VB.TextBox txtForm Height = 285 Index = 5 Left = 1785 TabIndex = 10 Top = 1695 Width = 2550 End Begin VB.TextBox txtForm Height = 285 Index = 4 Left = 1785 TabIndex = 4 Top = 1395 Width = 2550 End Begin VB.TextBox txtForm Height = 285 Index = 3 Left = 1785 TabIndex = 3 Top = 1095 Width = 2550 End Begin VB.TextBox txtForm Height = 285 Index = 2 Left = 1785 TabIndex = 2 Top = 795 Width = 2550 End Begin VB.TextBox txtForm Height = 285 Index = 1 Left = 1785 TabIndex = 1 Top = 495 Width = 2550 End Begin VB.TextBox txtForm Enabled = 0 'False Height = 285 Index = 0 Left = 1785 TabIndex = 0 Top = 180 Width = 2550 End Begin VB.Label lblForm BackStyle = 0 'Transparent Caption = "State" Height = 255 Index = 5 Left = 840 TabIndex = 11 Top = 1710 Width = 1470 End Begin VB.Label lblForm BackStyle = 0 'Transparent Caption = "City" Height = 255 Index = 4 Left = 840 TabIndex = 9 Top = 1410 Width = 1470 End Begin VB.Label lblForm BackStyle = 0 'Transparent Caption = "Address" Height = 255 Index = 3 Left = 840 TabIndex = 8 Top = 1110 Width = 1470 End Begin VB.Label lblForm BackStyle = 0 'Transparent Caption = "First Name" Height = 255 Index = 2 Left = 840 TabIndex = 7 Top = 810 Width = 1470 End Begin VB.Label lblForm BackStyle = 0 'Transparent Caption = "Last Name" Height = 255 Index = 1 Left = 840 TabIndex = 6 Top = 510 Width = 1470 End Begin VB.Label lblForm BackStyle = 0 'Transparent Caption = "ID" Height = 255 Index = 0 Left = 840 TabIndex = 5 Top = 195 Width = 1470 End Attribute VB_Name = "frmNames" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Private oNames As Names Private bLoaded As Boolean '------------------------------------------------------------------------' Private Sub cmdName_Click(Index As Integer) Select Case Index Case 0 '--New With oNames If cmdName(1).Enabled Then .IsNew = False .Save End If Call .Add End With cmdName(1).Enabled = True cmdName(2).Enabled = True Case 1 '--Save oNames.IsNew = False Call oNames.Save cmdName(1).Enabled = False cmdName(2).Enabled = False Case 2 '--Cancel Unload Me Exit Sub Case 3 '--Delete With oNames Call .Delete(.ID) '-- if no records are left, then you need to display a blank record If Not .MoveFirst Then Call .Add End With cmdName(1).Enabled = False cmdName(2).Enabled = False Case 4 '--Next If cmdName(1).Enabled Then oNames.IsNew = False oNames.Save Else oNames.CancelUpdate End If If Not oNames.MoveNext Then Call oNames.MoveLast cmdName(1).Enabled = False cmdName(2).Enabled = False Case 5 '--Previous If cmdName(1).Enabled Then oNames.IsNew = False oNames.Save Else oNames.CancelUpdate End If If Not oNames.MovePrevious Then Call oNames.MoveFirst cmdName(1).Enabled = False cmdName(2).Enabled = False End Select Call FillForm(oNames.ID) txtForm(1).SetFocus End Sub '------------------------------------------------------------------------' Private Sub Form_Activate() With oNames .Filter = "ORDER BY LName" .Requery If Not .MoveFirst Then .Add .Save .MoveFirst End If End With Call FillForm(oNames.ID) txtForm(1).SetFocus End Sub '------------------------------------------------------------------------' Private Sub Form_Load() Set oNames = New Names End Sub '------------------------------------------------------------------------' Private Sub Form_Unload(Cancel As Integer) oNames.CancelUpdate Set oNames = Nothing Call EndApp End Sub '------------------------------------------------------------------------' Private Sub FillForm(ID As Long) '-- If this form is a property dialog style, then apply a filter and requery... '-- if this form uses next and previous buttons, then you should leave the '-- entire recordset open and skip using the ID bLoaded = False With oNames ' .Filter = "WHERE Names.ID = " & CStr(ID) '-- Limit the class ' .Requery '-- Reset the class' recordset '-- Fill the form fields txtForm(0) = .ID txtForm(1) = .lname txtForm(2) = .fname txtForm(3) = .address txtForm(4) = .city txtForm(5) = .state End With bLoaded = True cmdName(1).Enabled = False cmdName(2).Enabled = False End Sub '------------------------------------------------------------------------' Private Sub txtForm_Change(Index As Integer) If bLoaded Then cmdName(1).Enabled = True cmdName(2).Enabled = True With oNames Select Case Index ' Case 0: .ID = txtForm(Index) Case 1: .lname = txtForm(Index) Case 2: .fname = txtForm(Index) Case 3: .address = txtForm(Index) Case 4: .city = txtForm(Index) Case 5: .state = txtForm(Index) End Select End With End If End Sub